import java.util.Vector;

import junit.framework.TestCase;


public class DomainLogicTest extends TestCase {
	
	DataBase dB = new DataBase();
	
	public void testDomainLogic() {
		DomainLogic dL = new DomainLogic(dB);
		
		assertTrue(dL.getUser()==null);
		assertTrue(dL.getDataBase()==dB);
	}

	public void testSetUser() {
		User u2 = new User("Tester","1234","admin");
		DomainLogic dL = new DomainLogic(dB);
				
		assertTrue(dL.getUser()==null);
		dL.setUser(u2);
		assertTrue(dL.getUser()==u2);
	}

	public void testGetUser() {
		User u2 = new User("Tester","1234","admin");
		DomainLogic dL = new DomainLogic(dB);
		
		assertTrue(dL.getUser()!=u2);
		dL.setUser(u2);
		assertTrue(dL.getUser()!=null);
		assertTrue(dL.getUser()==u2);
	}

	public void testSetDataBase() {
		DomainLogic dL = new DomainLogic(dB);
		
		assertTrue(dL.getDataBase()==dB);
		dL.setDataBase(dB);
		assertTrue(dL.getDataBase()==dB);
	}

	public void testLogOn() {
		DomainLogic dL = new DomainLogic(dB);
		
		String name = "jovan";
		String password = "password";
		assertTrue(dL.logOn(name, password));
		assertTrue(dL.getUser().getUsername()==name);
		
		assertFalse(dL.logOn("TESTER","INCORRECT"));
		assertTrue(dL.getUser().getUsername()==name);
	}

	public void testLogOff() {
		DomainLogic dL = new DomainLogic(dB);
		
		assertTrue(dL.getUser()==null);
		
		String name = "jovan";
		String password = "password";
		assertTrue(dL.logOn(name, password));
		
		dL.logOff();
		assertTrue(dL.getUser()==null);
		
	}

	public void testFindRestaurants() {
		DataBase dB = new DataBase();
		DomainLogic dL = new DomainLogic(dB);
		
		String foodType = Constants.BURGERS;
		String zipCode = "92122";
		Preferences pref = new Preferences();
		Vector<Restaurant> result = dL.findRestaurants(foodType, zipCode, pref);
		assertTrue(!result.isEmpty());
		
		foodType = Constants.ITALIAN;
		zipCode = "92122";
		result = dL.findRestaurants(foodType, zipCode, pref);
		assertTrue(result.isEmpty());
		
		foodType = Constants.BURGERS;
		zipCode = "92222";
		result = dL.findRestaurants(foodType, zipCode, pref);
		assertTrue(result.isEmpty());
	}
	
	public void testRegisterUser() {
		DataBase dB = new DataBase();
		DomainLogic dL = new DomainLogic(dB);
		
		dL.registerUser("test", "test", null);
		assertTrue(dB.getUser("test")!=null);
	}
	/*
	public void testAddUserPreferences() {
		DataBase dB = new DataBase();
		DomainLogic dL = new DomainLogic(dB);
		UserPreferences uP = new UserPreferences("test", "zip", "type", new Preferences());
		dL.addUserPreferences(uP);
		assertTrue(dL.getUserPreferences().contains(uP));
	}
	
	public void testGetUserPreferences() {
		DataBase dB = new DataBase();
		DomainLogic dL = new DomainLogic(dB);
		UserPreferences uP = new UserPreferences("test", "zip", "type", new Preferences());
		dL.addUserPreferences(uP);
		assertTrue(dL.getUserPreferences().contains(uP));
	}*/
	
	public void testGetRestaurant() {
		DataBase dB = new DataBase();
		DomainLogic dL = new DomainLogic(dB);
		assertTrue(dL.getRestaurant("KFC")!=null);
	}
	
	public void testAddRestaurant() {
		DataBase dB = new DataBase();
		DomainLogic dL = new DomainLogic(dB);
		dL.addRestaurant("test", "", "", "", null);
		assertTrue(dB.getRestaurant("test")!=null);
	}
	
	public void testEditRestaurant() {
		DataBase dB = new DataBase();
		DomainLogic dL = new DomainLogic(dB);
		dL.editRestaurant("KFC", "test", "", "", null);
		assertTrue(dB.getRestaurant("KFC").getAddress().equals("test"));
	}
	
	public void testDeleteRestaurant() {
		DataBase dB = new DataBase();
		DomainLogic dL = new DomainLogic(dB);
		dL.deleteRestaurant("KFC");
		assertTrue(dB.getRestaurant("KFC")==null);
	}
	
	public void testShowRestaurantNames() {
		DataBase dB = new DataBase();
		DomainLogic dL = new DomainLogic(dB);
		assertTrue(dB.getRestaurants().keySet().containsAll(dL.showRestaurantNames()));
	}
}
